package ngat.oss;

import ngat.message.OSS.*;
import ngat.util.logging.*;
import ngat.phase2.*; 
import ngat.instrument.*;
import ngat.phase2.nonpersist.*;

import java.util.*;
import java.io.*;

import jyd.dbms.*;
import jyd.storable.*;
import jyd.collection.*;

/**
 * Action:Remove a TAG.
 * @author S.N.Fraser
 * $Id: DELETE_TAGImpl.java,v 1.3 2007/07/05 11:49:04 snf Exp $
 */
public class DELETE_TAGImpl extends TransactionImpl {
    
    /** The path used to locate the TAG in the OSS database. */
    protected Path tagPath;
      
    /** Create a DELETE_TAGImpl for the supplied request.*/
    public DELETE_TAGImpl(DELETE_TAG request) {
	super(request);
	this.tagPath = request.getTagPath();
    }
    
    /**
     * Removes the specified TAG from the ODB.
     * @return Boolean to indicate success.
     */
    public TRANSACTION_DONE exec() { 

	Transaction t = null;
	try {
	    t = Transaction.current();
	    
	    Tag  tag     = OSS_Utilities.fetchTag(tagPath);

	    if (tag == null)
		return error(TRANSACTION.PATH_RESOLUTION_ERROR,
			     "No such Tag ["+tagPath+"] found");
	    
	    Root root = OSS_Utilities.fetchRoot();
	    root.deleteTag(tag);

	    DELETE_TAG_DONE done = new DELETE_TAG_DONE(id); 
	    done.setSuccessful(true);
	    done.setRemoved(true);
	    return done;
	    
	} finally {
	    t.commit();
	}
    }
    
}

/** $Log: DELETE_TAGImpl.java,v $
/** Revision 1.3  2007/07/05 11:49:04  snf
/** checkin
/**
/** Revision 1.2  2007/02/27 11:48:55  snf
/** added target user
/**
/** Revision 1.1  2007/02/23 11:23:50  snf
/** Initial revision
/** */
